import React from 'react';
import { Tree, Spin, Button } from 'antd';

interface DepartmentTreeProps {
  departments: any[];
  loading: boolean;
  selectedDeptId: number | null;
  onSelect: (id: number) => void;
  onAdd: () => void;
  onEdit: () => void;
  onDelete: () => void;
}

const DepartmentTree: React.FC<DepartmentTreeProps> = ({
  departments, loading, selectedDeptId, onSelect, onAdd, onEdit, onDelete
}) => {
  return (
    <Spin spinning={loading}>
      <div style={{ marginBottom: 12 }}>
        <Button type="primary" size="small" onClick={onAdd}>新增部门</Button>
      </div>
      <Tree
        treeData={departments}
        selectedKeys={selectedDeptId ? [selectedDeptId] : []}
        onSelect={keys => onSelect(keys[0] as number)}
        // 这里可扩展右键菜单、编辑、删除等
      />
    </Spin>
  );
};

export default DepartmentTree; 